package org.xfy.ymcc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.xfy.common.result.JsonResult;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@RestController
public class TokenController {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @GetMapping("/createToken/{courseId}")
    public JsonResult createToken(@PathVariable("courseId")String courseId){
        String token = UUID.randomUUID().toString();
        redisTemplate.opsForValue().set(courseId,token,30, TimeUnit.MINUTES);
        return JsonResult.success().setData(token);
    }
}
